<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin/head :: head" th:with="title=菜单列表">
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <a class="layui-btn" lay-submit lay-filter="data-search-btn">搜索</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <div class="layui-btn-group">
            <button class="layui-btn data-add-btn">添加</button>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{# if(d.jobStatusStr=='正常'||d.jobStatusStr=='运行中'){ }}
            <a class="layui-btn layui-btn-xs  layui-btn-warm" lay-event="pause">暂停</a>
            {{#  } else { }}
            <a class="layui-btn layui-btn-xs" lay-event="resume">恢复</a>
            {{# } }}
            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="nowRun">立即执行</a>
            <a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="deletejob">删除</a>
        </script>
    </div>
</div>
<script type="text/javascript" th:inline="none">
    //layer   使用教程https://www.layui.com/doc/modules/laydate.html

    layui.use(['form','table','laydate','liuQi'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            liuQi = layui.liuQi;
        var table_height=liuQi.getTableHeight($("fieldset").height());
        form.render();

        table.render({
            elem: '#currentTableId',
            url: '/admin/task/queryList',
            cellMinWidth: 80,
            cols: [[
                {field: 'jobName', title: '任务名称',align: "center"},
                {field: 'jobGroup', title: '任务组',align: "center"},
                {field: 'jobDescription', title: '任务描述',align: "center"},
                {field: 'jobStatusStr', title: '任务状态',align: "center"},
                {field: 'cronExpression', title: '任务表达式',align: "center"},
                {field: 'preTime', title: '上次执行时间',align: "center"},
                {field: 'nextTime', title: '下次执行时间',align: "center"},
                {field: 'createTime', title: '创建时间',align: "center"},
                {title: '操作', width: '20%', templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            height:table_height,
            limits: [10, 20, 50, 100],
            limit: 20,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = data.field;

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: result
            }, 'data');
            return false;
        });


        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            //参数    url，参数，标题，宽度%（默认70%），高度%（默认70%）
            liuQi.openDialog('/admin/task/toAdd',{},"添加任务",'50','55');
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'pause') {
                liuQi.ajaxRefreshTable('/admin/task/pausejob',{"jobClassName":data.jobName,"jobGroupName":data.jobGroup});
            } else if (obj.event === 'resume') {
                liuQi.ajaxRefreshTable('/admin/task/resumejob',{"jobClassName":data.jobName,"jobGroupName":data.jobGroup});
            }else if (obj.event === 'deletejob') {
                liuQi.ajaxRefreshTable('/admin/task/deleteJob',{"jobClassName":data.jobName,"jobGroupName":data.jobGroup});
            }else if (obj.event === 'nowRun') {
                liuQi.ajaxRefreshTable('/admin/task/nowRun',{"jobClassName":data.jobName,"jobGroupName":data.jobGroup});
            }else if (obj.event === 'edit') {
                liuQi.openDialog('/admin/task/toUpdate',{"jobClassName":data.jobName,
                    "jobGroupName":data.jobGroup,
                    "cronExpression":data.cronExpression,
                    "description":data.jobDescription
                },"编辑任务",'50','55')
            }
        });
    });

</script>
</body>
</html>